﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BTL
{
    public partial class cthdnhap : Form
    {
        VO.cthd _chhdVO;
        BAL.cthdnhap _cthdBAL;
        public cthdnhap()
        {
            InitializeComponent();
        }
        private void data()
        {
            _chhdVO = new VO.cthd();
            _chhdVO.Mahd = box_mahd.Text;
            _chhdVO.Mas = box_masach.Text;
            _chhdVO.Tens = box_sl.Text;
        }
        private void bt_them_Click(object sender, EventArgs e)
        {
            
                    if(box_mahd.Text!="")
                    {
                try
                {
                    _cthdBAL = new BAL.cthdnhap();
                    data();
                    _cthdBAL.cthdnhap_them(_chhdVO);
                    cthdnhap_Load(sender, e);
                    MessageBox.Show("Thành công", "Them Thành Công", MessageBoxButtons.OK);
                }
                catch
                {
                    MessageBox.Show("Lỗi", "Có lỗi xảy ra, xem help", MessageBoxButtons.OK);
                }
                    }
            else
                    {
                        MessageBox.Show("Lỗi", "Không để trống mã hóa đơn", MessageBoxButtons.OK);
                    }
        }

        private void buttonX1_Click(object sender, EventArgs e)
        {
                _cthdBAL = new BAL.cthdnhap();
                dataGridViewctHoaDon.DataSource = _cthdBAL.cthdnhap_xem();
        }
        private void datadind()
        {
            box_mahd.DataBindings.Clear();
            box_mahd.DataBindings.Add("text",dataGridViewctHoaDon.DataSource,"MaHD");
            box_masach.DataBindings.Clear();
            box_masach.DataBindings.Add("text", dataGridViewctHoaDon.DataSource, "MaS");
            box_sl.DataBindings.Clear();
            box_sl.DataBindings.Add("text", dataGridViewctHoaDon.DataSource, "TenS");
        }
        private void cthdnhap_Load(object sender, EventArgs e)
        {
            buttonX1_Click(sender,e);
            datadind();
        }

        private void bt_sua_Click(object sender, EventArgs e)
        {
            try
            {
                _cthdBAL = new BAL.cthdnhap();
                data();
                _cthdBAL.cthdnhap_sua(_chhdVO);
                cthdnhap_Load(sender, e);
                MessageBox.Show("Thành công", "Sua Thành Công", MessageBoxButtons.OK);
            }
            catch
            {
                MessageBox.Show("Lỗi", "Có lỗi xảy ra, xem help", MessageBoxButtons.OK);
            }
        }

        private void bt_xoa_Click(object sender, EventArgs e)
        {
            try
            {
                _cthdBAL = new BAL.cthdnhap();
                data();
                _cthdBAL.cthdnhap_xoa(_chhdVO);
                cthdnhap_Load(sender, e);
                MessageBox.Show("Thành công", "Xoa Thành Công", MessageBoxButtons.OK);
            }
            catch
            {
                MessageBox.Show("Lỗi", "Có lỗi xảy ra, xem help", MessageBoxButtons.OK);
            }
        }

        private void bt_thoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void buttonX2_Click(object sender, EventArgs e)
        {
            frmHelp _fm = new frmHelp();
            _fm.Show();
        }
    }
}
